import { setGlobal } from '@swda/utils';

//-----------------------------------------------------------------------------
// Window_ActorPage
//
// 状态、技能、装备等选单切换角色
function Window_ActorPage() {
    this.initialize.apply(this, arguments);
}

Window_ActorPage.prototype = Object.create(Window_Selectable.prototype);
Window_ActorPage.prototype.constructor = Window_ActorPage;



Window_ActorPage.prototype.initialize = function() {
    Window_Selectable.prototype.initialize.call(this, 0, 0, 0, 0);
    this._scene = null;
    this.createButtons();
    this.placeButtons();
    this.opacity = 0;
    this.refresh();
};

Window_ActorPage.prototype.setScene = function(scene) {
    this._scene = scene
};

Window_ActorPage.prototype.createButtons = function() {
    var bitmap = ImageManager.loadBitmap('img/system/UI/', 'ButtonSetShop');
    var buttonWidth = 48;
    var buttonHeight = 48;
    this._buttons = [];
    for (var i = 0; i < 2; i++) {
        var button = new Sprite_Button();
        var x = buttonWidth * (i+1);
        var w = buttonWidth;
        button.bitmap = bitmap;
        button.setColdFrame(x, 0, w, buttonHeight);
        button.setHotFrame(x, buttonHeight, w, buttonHeight);
        button.setOnFrame(x, 2*buttonHeight, w, buttonHeight);
        button.visible = true;
        button.enabled = true;
        this._buttons.push(button);
        this.addChild(button);
    }
    this._buttons[0].setClickHandler(this.onButtonLeft.bind(this));
    this._buttons[1].setClickHandler(this.onButtonRight.bind(this));
};

Window_ActorPage.prototype.placeButtons = function() {
    var buttonWidth = 160;   //32
    this._buttons[0].x = this.buttonX() - buttonWidth;
    this._buttons[0].y = this.buttonY();
    this._buttons[1].x = this.buttonX() + buttonWidth;
    this._buttons[1].y = this.buttonY();
};

Window_ActorPage.prototype.refresh = function() {
    this.contents.clear();
    this.refreshButtonEnabled();
};

Window_ActorPage.prototype.refreshButtonEnabled = function() {
    if (!this.changeEnable()){
        this._buttons[0].enabled = false;
        this._buttons[1].enabled = false;
        this._buttons[0].visible = false;
        this._buttons[1].visible = false;
    }else{
        this._buttons[0].enabled = true;
        this._buttons[1].enabled = true;
        this._buttons[0].visible = true;
        this._buttons[1].visible = true;
    }
};

Window_ActorPage.prototype.buttonX = function() {
    return 210-32;
};

Window_ActorPage.prototype.buttonY = function() {
    return 300;
};


Window_ActorPage.prototype.changeEnable = function() {
    return $gameParty.members().length > 1;

};


Window_ActorPage.prototype.onButtonLeft = function() {
    this._scene.previousActor();
    SoundManager.playCursor();
};

Window_ActorPage.prototype.onButtonRight = function() {
    this._scene.nextActor();
    SoundManager.playCursor();
};


setGlobal('Window_ActorPage', Window_ActorPage)